package org.zjvis.datascience.common.graph.model;

import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.zjvis.datascience.common.util.FileUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
public class DefaultNodeStyle {
    private Integer size;

    private JSONObject style ;

    //avoid json ref
    private String labelCfg;

    private List<String> colorLoop = new ArrayList<>();

    private Integer colorLoopSize;

    private String defaultColor;

    private String defaultType = "circle";

    public DefaultNodeStyle() {
        colorLoop = Arrays.asList(
                "#A4ABFB",
                "#F5A4AC",
                "#A2DCED",
                "#F9D26F",
                "#73A0FA",
                "#AED495",
                "#6E80A2",
                "#DDB6FF",
                "#FDB69E",
                "#16A37E",
                "#7751FF",
                "#F3470D",
                "#5AB7DA",
                "#3464FF"
        );

        String json = null;
        try {
            json = FileUtil.inputStream2String(DefaultNodeStyle.class.getClassLoader().getResourceAsStream("style/default_style.json"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONObject obj = JSONObject.parseObject(json);
        size = obj.getInteger("size");
        style = obj.getJSONObject("style");
        labelCfg = obj.getJSONObject("labelCfg").toJSONString();
        defaultColor = obj.getString("defaultFill");

        try {
            json = FileUtil.inputStream2String(DefaultNodeStyle.class.getClassLoader().getResourceAsStream("style/color_loop.json"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        colorLoop = JSONObject.parseArray(json).toJavaList(String.class);
        colorLoopSize = colorLoop.size();
    }
}
